$(function(){
  console.log('jquery的加载后立即执行');
  const millName = $.request.queryString["millName"];
  console.log(`即将清理染厂${millName}的心跳日志`);
  clearHeartBeatLog(millName);
});


// 清除心跳日志
function clearHeartBeatLog(millName){
  const url = `https://www.xdfznh.club/wxpadbe/heartbeat/deleteByMill/${millName}`;
  $.ajax({
      async: true,
      type : "GET",
      contentType: "application/json;charset=UTF-8",
      url : url,
      success : function(res) {
        const code = parseInt(res.code);
        if(code !== 1) {
          console.log(`清除${millName}的心跳日志时后台响应了错误码：${code}，提示消息：${res.msg}`);
          return
        }

        $(`#caption`).html(`已清除${millName}的所有心跳日志！`);
      },
      error : function(e){
        console.log(e.status);
        console.log(e.responseText);
      },
      complete: function () {
        console.log('清理心跳日志的ajax.complete');
      }
  })
}

$.request = (function () { 
    var apiMap = {}; 
    function request(queryStr) { 
        var api = {}; 
        if (apiMap[queryStr]) { return apiMap[queryStr]; } 
        api.queryString = (function () { 
            var urlParams = {}; 
            var e, 
            d = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); }, 
            q = queryStr.substring(queryStr.indexOf('?') + 1), 
            r = /([^&=]+)=?([^&]*)/g; 
            while (e = r.exec(q))     urlParams[d(e[1])] = d(e[2]);
            return urlParams; 
        })(); 
        api.getUrl = function () { 
            var url = queryStr.substring(0, queryStr.indexOf('?') + 1); 
            for (var p in api.queryString) { url += p + '=' + api.queryString[p] + "&";        } 
            if (url.lastIndexOf('&') == url.length - 1) { return url.substring(0, url.lastIndexOf('&')); } 
            return url; 
        } 
        apiMap[queryStr] = api; 
        return api; 
    } 
    $.extend(request, request(window.location.href)); 
    return request; 
})();
